import AsyncStorage from '@react-native-community/async-storage';
import { STORAGE_KEY_AIP_TOKEN } from '../constant';

let accessToken = '';

AsyncStorage.getItem(STORAGE_KEY_AIP_TOKEN).then((res: any): void => {
  if (res) {
    const token = JSON.parse(res);
    accessToken = token;
  }
});

export const setAssessToken = (token: string): void => {
  accessToken = token;
  AsyncStorage.setItem(STORAGE_KEY_AIP_TOKEN, JSON.stringify(token));
};

export const getAssessToken = (): string => {
  return accessToken;
};
